<!-- 分类页面 -->

<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="./css/classification.css" />
		<script src="js/mui.min.js"></script>
		<script src="js/jquery-3.2.1.min.js"></script>
		<script type="text/javascript">
			mui.init({
				pullRefresh: {
					container: "#class-content", //下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
					down: {
						style: 'circle', //必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
						color: '#55aaff', //可选，默认“#2BD009” 下拉刷新控件颜色
						height: '50px', //可选,默认50px.下拉刷新控件的高度,
						range: '100px', //可选 默认100px,控件可下拉拖拽的范围
						offset: '0px', //可选 默认0px,下拉刷新控件的起始位置
						auto: false, //可选,默认false.首次加载自动上拉刷新一次
						callback: function() { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
							classification.getFirstTitle();			
							mui.toast("已刷新");
							setTimeout("mui('#class-content').pullRefresh().endPulldownToRefresh()", 1000);
						}
					}
				}
			})

			var backButtonPress = 0;
			mui.back = function() {
				backButtonPress++;
				if (backButtonPress > 1) {
					//如果当前用户登录则监控其退出
					if (user.userId != null) {
						//向服务器发送请求
						$.ajax({
							url: "http://39.98.158.247:8040/user/logout",
							dataType: "json",
							type: "POST",
							data: {
								"_method": "PUT",
								"user_id": localStorage.getItem("user"),
							},
							contentType: "application/x-www-form-urlencoded",
							xhrFields: {
								withCredentials: true
							},
							//请求成功时
							success: function(data) {
								console.log(data);
							},
							//请求发生错误
							error: function() {
								console.log("request error");
							},
						})
					}
					localStorage.clear();
					plus.runtime.quit();
				} else {
					plus.nativeUI.toast('再按一次退出应用');
				}
				//这里必须有延迟恢复机制
				setTimeout(function() {
					backButtonPress = 0;
				}, 2000);
				return false;
			}
		</script>
		<script src="js/user.js"></script>
		<script src="js/Classification.js"></script>
		<link href="css/classification.css" rel="stylesheet" />

	</head>

	<body>

		<!-- 顶部搜索框放在header里，以防下方内容上滑时遮罩搜索框 -->
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">分类</h1>
			<div>
				<div class="mui-input-row mui-search">
					<input type="search" id="search" class="mui-input-clear" value="请输入商品名称" style="color:#AAAAAA;text-align: center;">
				</div>
			</div>
		</header>
		<div id="class-content">
			<!-- mui-content承载左侧菜单栏和右侧二级分类-->
			<!-- 一级分类 -->
			<div class="first-title">
			</div>
			<div class="content">
				<!-- 二级分类 -->
				<div class="second-title">
				</div>
			</div>
		</div>
		<!-- 底部导航 -->
		<nav class="mui-bar mui-bar-tab" id="nav">
		</nav>
	</body>

	<script src="js/search.js"></script>
	<!-- nav控制下边script作用范围 -->
	<script>
		mui('nav').on('tap', 'a', function() {
			document.location.href = this.href;
		})
	</script>
</html>
